///********************************************************************
///* Copyright © 2012 fishr (fishr.flash@gmail.com)  
///********************************************************************


package su.fishr.social_network.OK.uploadV2.requests 
{
	
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import su.fishr.social_network.OK.uploadV2.utils.CalculateHash;
	
   

	/** 
	 * @private 
	 * 
	 * Инициализирует процедуру загрузки фотографий.
	 * Использует метод photosV2.getUploadUrl АПИ ОК.
	 * 
	 * @playerversion          Flash 10
	 * @langversion            3.0
	 * @author                 fishr
	 * @created                30.05.2012 2:38
	 * @since                  30.05.2012 2:38
	 */
	public class GetUploaderURL extends Requester
	{
	/**-------------------------------------------------------------------------------
	* 
	*	   						V A R I A B L E ' S 	
	* 
	* --------------------------------------------------------------------------------
	*/
	//{
		static private const AUTHOR:String = "fishr (fishr.flash@gmail.com)";
	//}
	
	/**-------------------------------------------------------------------------------
	* 
	*	 						P R O P E R T I E S 	
	* 
	* --------------------------------------------------------------------------------
	*/
	//{
	
	//}
	/**-------------------------------------------------------------------------------
	* 
	*								P U B L I C 	
	* 
	* --------------------------------------------------------------------------------
	*/
	//{
		/**
		 * Конструктор
		 * 
		 * @param	callback
		 * @param	errorCall
		 * @param	parameters
		 * @param	request
		 */
		public function GetUploaderURL(callback:Function, errorCall:Function, parameters:Object, request:URLRequest = null)
		{
			super(callback, errorCall, request);
			
			init( parameters );
		}
		
		
		
		
	//}
	
	/**-------------------------------------------------------------------------------
	* 
	*								P R I V A T E 	
	* 
	* --------------------------------------------------------------------------------
	*/	
	//{
		private function init(parameters:Object):void 
		{
			
			
			var request:String;
			request = parameters.api_server + "api/photosV2/getUploadUrl";
			
			var data:Object = new Object();
			data.application_key = parameters.application_key;
			data.session_key = parameters.session_key;
			
			data.sig = CalculateHash( data, parameters.session_secret_key );
			
			
			var variables:URLVariables = new URLVariables();
			
			for ( var name:String in data )
			{
				variables[ name ] = data[ name ];
			}
			
			
			var urlRequest:URLRequest = new URLRequest( request);
			urlRequest.data = variables;
			
			super.load( urlRequest );
			
		}
	//}
		
		
	}

}